import { defineStore } from 'pinia';
import piniaPersistConfig from '@/stores/helper/persist';
import { ref } from 'vue';
import type {NovelDictsEnity} from "@/api/types/novel/novelDict";

export const useNovelOptionsStore = defineStore(
  'options',
  () => {
    const isLoaded = ref(false);
    const dictOptions = ref<Record<string, NovelDictsEnity[]>>({});

    // async function getAllDictList() {
    //   if (isLoaded.value) return;
    //   const { data } = await getAllDict();
    //   dictOptions.value = data;
    //   isLoaded.value = true;
    // }

    function getDictOptions(type: string): NovelDictsEnity[] {
      return dictOptions.value[type] || [];
    }

    function setReloadOptions() {
      isLoaded.value = false;
    }

    // async function getDictByCodes(typeCodes: string[]) {
    //   const { data } = await getDictByCode({ typeCode: typeCodes });
    //   typeCodes.forEach(code => {
    //     dictOptions.value[code] = data[code];
    //   });
    // }

    return {
      isLoaded,
      dictOptions,
      getDictOptions,
      setReloadOptions,
    };
  },
  {
    persist: piniaPersistConfig('options')
  }
);
